


//定义变量
const state = {
    num: 0, //目前执行异步请求的数量
    progress:0,
}

//获取
var getters = {
    isShow(state) {
        return state.num > 0 ? true :false;
    },
    getProgress(state){
        return state.progress
    }
}

//设置
const mutations = {
    setNum(state, val) {
        if (val === 0) {//error和页面跳转时，直接重置
            state.num = 0;
        }
        else {
            state.num = val ? ++state.num : --state.num;
        }
    },
    setProgress(state,val){
        state.progress = val
    },
    clearProgress(state){
        state.progress = 0
    }
}

//异步
const actions = {
    setLoading(context, val) {
        context.commit("setNum", val);
    }
}



export default {
    namespaced: true,
    state,
    getters,
    actions,
    mutations,
}